const router = require('koa-router')();
const fs = require('fs-extra');
const path = require('path');
const {dataPath} = require('../config');
router.post('/',async (ctx) => {
    try {
        let cont = await fs.readFile(dataPath);
        cont = JSON.parse(cont);
        cont.answerCount = (cont.answerCount || cont.answerCount == 0) ? (cont.answerCount + 1) : 1;
        await fs.writeFile(dataPath,JSON.stringify(cont));
        ctx.body = {
            code: 1,
            data:cont,
            msg:'success'
        }
    } catch(error){
        ctx.body = {
            code: 0,
            msg:'error'
        }
        ctx.status = 500;
    }
    
})

module.exports = router;